added samples
[windows-sources.git] / sdk / samples / all in on code / Visual Studio 2010 / VBASPNETInheritingFromTreeNode / CustomTreeView.vb
blobcf0ef857fa468075c13edd4804edd594a29c46d3
1 '****************************** Module Header ******************************\
2 ' Module Name: CustomTreeView.vb
3 ' Project: VBASPNETInheritingFromTreeNode
4 ' Copyright (c) Microsoft Corporation
6 ' This file defines a CustomTreeView control which's tree nodes contain a Tag
7 ' property. The Tag property can be used to store a custom object.
9 ' This source is subject to the Microsoft Public License.
10 ' See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
11 ' All other rights reserved.
13 '*****************************************************************************/
15 Public Class CustomTreeView
16 Inherits TreeView
17 ''' <summary>
18 ''' Returns a new instance of the TreeNode class. The CreateNode is a helper method.
19 ''' </summary>
20 Protected Overrides Function CreateNode() As TreeNode
21 Return New CustomTreeNode(Me, False)
22 End Function
23 End Class
25 Public Class CustomTreeNode
26 Inherits TreeNode
27 ''' <summary>
28 ''' Gets or sets the object that contains data about the tree node.
29 ''' </summary>
30 Public Property Tag As Object
32 Public Sub New()
33 MyBase.New()
34 End Sub
36 Public Sub New(ByVal owner As TreeView, ByVal isRoot As Boolean)
37 MyBase.New(owner, isRoot)
38 End Sub
40 ''' <summary>
41 ''' Restores view-state information from a previous page request that
42 ''' was saved by the SaveViewState method.
43 ''' </summary>
44 ''' <param name="state">
45 ''' An Object that represents the control state to be restored.
46 ''' </param>
47 Protected Overrides Sub LoadViewState(ByVal state As Object)
48 Dim arrState As Object() = TryCast(state, Object())
50 Me.Tag = arrState(0)
51 MyBase.LoadViewState(arrState(1))
52 End Sub
54 ''' <summary>
55 ''' Saves any server control view-state changes that have occurred
56 ''' since the time the page was posted back to the server.
57 ''' </summary>
58 ''' <returns>
59 ''' Returns the server control's current view state. If there is no
60 ''' view state associated with the control, this method returns null.
61 ''' </returns>
62 Protected Overrides Function SaveViewState() As Object
63 Dim arrState As Object() = New Object(1) {}
64 arrState(1) = MyBase.SaveViewState()
65 arrState(0) = Me.Tag
67 Return arrState
68 End Function
69 End Class